from pages.base_page import BasePage
from selenium.webdriver.common.by import By


class CustomerHomePage(BasePage):
    url = '/crm/index.php?m=customer'
    #定位器
    new_customer_locator = (By.CSS_SELECTOR, '.btn-primary')
    add_customer_name_locator = (By.ID, 'name')
    save_add_customer_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')
    save_success_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')
    first_customer_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[2]')
    origin_locator = (By.ID, 'origin')
    edit_save_locator = (By.CSS_SELECTOR,'#form1 > table > tfoot > tr > td > input.btn.btn-primary')
    edit_success_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    batch_opereate_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > ul > div > a')
    batch_del_locator = (By.ID,'delete')
    delete_info_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-error')


    #点击新建客户
    def click_new_customer(self):
        self.driver.find_element(*self.new_customer_locator).click()
    def add_customer_name(self,customer_name):
        self.driver.find_element(*self.add_customer_name_locator).send_keys(customer_name)

    def click_save_customer(self):
        self.driver.find_element(*self.save_add_customer_locator).click()

    def add_customer_success(self):
        return self.driver.find_element(*self.save_success_locator).text

    def edit_first_customer(self):
        self.driver.find_element(*self.first_customer_locator).click()

    def edit_customer_origin(self):
        return self.driver.find_element(*self.origin_locator)
    def click_edit_save(self):
        self.driver.find_element(*self.edit_save_locator).click()

    def edit_customer_success(self):
        return self.driver.find_element(*self.edit_success_locator).text

    def batch_operate_customer(self):
        self.driver.find_element(*self.batch_opereate_locator).click()
    def batch_del_customer(self):
        self.driver.find_element(*self.batch_del_locator).click()
    def batch_del_info(self):
        return self.driver.find_element(*self.delete_info_locator).text




